/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import dao.DienThoaiDAO;
import dao.util.HibernateUtil;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.hibernate.Query;
import org.hibernate.Session;
import pojo.Dienthoai;
import template.choosePage;

/**
 *
 * @author vinh
 */
@ManagedBean(name = "ViewDT")
@SessionScoped
public class ViewMobile {

    
    private static String amthanh= "MP3";
    public String getAmthanh() {
        return amthanh;
    }
    public void setAmthanh(String aAmthanh) {
        amthanh = aAmthanh;
    }
    
    
    private static String kichthuoc=" ";  
    public String getKichthuoc() {
        return kichthuoc;
    }
    public void setKichthuoc(String aKichthuoc) {
        kichthuoc = aKichthuoc;
    }
    
    private static String hienthi=" ";  
    public String getHienthi() {
        return hienthi;
    }
    public void setHienthi(String ahienthi) {
        hienthi = ahienthi;
    }
    
    
    private static String pin = "BL-4C";  
    public String getPin() {
        return pin;
    }
    public void setPin(String apin) {
        pin = apin;
    }
    

    private static String bonho=" ";
    public String getBonho() {
        return bonho;
    }
    public void setBonho(String aBonho) {
        bonho = aBonho;
    }
    
    
    private static String camera =" ";
    public String getCamera() {
        return camera;
    }
    public void setCamera(String aCamera) {
        camera = aCamera;
    }
    
    
    public void getDienthoaitheonhieutieuchi()
    {
        choosePage.page="LoaiDienThoai";
        DienThoaiDAO dtdao = new DienThoaiDAO();
        System.out.println(camera + "---------------------------------------------------------");
        System.out.println(amthanh + "*********************************************************");
        System.out.println(hienthi + "-----------");
        System.out.println(pin);
        System.out.println(bonho);
        System.out.println(kichthuoc);
        
        DSDienThoai = dtdao.getDienthoaitheonhieutieuchi(amthanh, camera, pin, bonho, hienthi, kichthuoc);
        
        if(DSDienThoai==null)
        {
            DSDienThoai = new ArrayList<Dienthoai>();
        }
    }
    
    /////////////////////////////////////////////////////////////////////
    static public ArrayList<Dienthoai> DSDienThoai = new ArrayList();

    private int trang=0;
    public ViewMobile() {
    }

    public ArrayList<Dienthoai> getDSDienThoai() {
        return DSDienThoai;
    }

    public void setDSDienThoai(ArrayList<Dienthoai> ds) {
        DSDienThoai = ds;
    }
public void TangTrang()
{
trang++;
}
public void giamTrang()
{
trang--;
}
    public void View() throws IOException {
        String uri = "/page/ViewMobile.xhtml";
        FacesContext.getCurrentInstance().getExternalContext().dispatch(uri);
    }

    public void setViewDT_NSX(String nsx) {
        choosePage.page="NhaSanXuat";
        trang =0;
        Session session = HibernateUtil.getSessionFactory().openSession();
        String hql = String.format("select obj from %s obj where obj.nhasanxuat.manhasanxuat like '%s'", Dienthoai.class.getName(), nsx);

        Query query = session.createQuery(hql);
        //query.setParameter(0,nsx)
        DSDienThoai = (ArrayList<Dienthoai>) query.list();
        session.close();
    }

    public void setViewDT_LDT(String loaiDT) {
        trang=0;
        choosePage.page="LoaiDienThoai";
        Session session = HibernateUtil.getSessionFactory().openSession();
        String hql = String.format("select obj from %s obj where obj.loaidienthoai.maloaidienthoai like '%s'", Dienthoai.class.getName(), loaiDT);

        Query query = session.createQuery(hql);
        //query.setParameter(0,nsx)
        DSDienThoai = (ArrayList<Dienthoai>) query.list();
        session.close();
    }
    public void setTrangChu()
    {
        DSDienThoai = new ArrayList();
    }

    /**
     * @return the trang
     */
    public int getTrang() {
        return trang;
    }

    /**
     * @param trang the trang to set
     */
    public void setTrang(int trang) {
        this.trang = trang;
    }
    ////////////////////////////////////////////////////////////////////////
    private static int giadt= 12;
    public int getGiadt() {
        return giadt;
    }
    public void setGiadt(int aGiadt) {
        giadt = aGiadt;
    }


    private static String hangdt="no";
    public String getHangdt() {
        return hangdt;
    }
    public  void setHangdt(String aHangdt) {
        hangdt = aHangdt;
    }
    
    
    private static String tendt="nokia";
    public String getTendt() {
        return tendt;
    }
    public  void setTendt(String aTendt) {
        tendt = aTendt;
    }
    
    
    public void getDienthoaitheogiavahang()
    {
        choosePage.page="LoaiDienThoai";
        DienThoaiDAO dtdao = new DienThoaiDAO();
        System.out.print(getHangdt()+"^^^^^^^");
        DSDienThoai = dtdao.getDienthoaitheogiavahang(getGiadt(),getHangdt().toString());
    }
    
    
    public void getDienthoaitheoten()
    {
        choosePage.page="LoaiDienThoai";
        DienThoaiDAO dtdao = new DienThoaiDAO();
        DSDienThoai = dtdao.getDienthoaitheoten(tendt);
    }
}
